<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('数据连接列表')" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <!--<div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <label>数据库IP地址：</label>
                                <input type="text" name="ipAddr"/>
                            </li>
                            &lt;!&ndash;<li>
                                <label>数据库端口：</label>
                                <input type="text" name="port"/>
                            </li>&ndash;&gt;
                            <li>
                                <label>数据库名称：</label>
                                <input type="text" name="naDb"/>
                            </li>
                            &lt;!&ndash;<li>
                                <label>数据库用户名：</label>
                                <input type="text" name="username"/>
                            </li>
                            <li>
                                <label>数据库密码：</label>
                                <input type="text" name="password"/>
                            </li>&ndash;&gt;
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>-->

            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <!-- 关键：用 d-flex（弹性布局）替代固定栅格，实现自适应 -->
                    <div class="select-list d-flex align-items-center flex-wrap" style="gap: 15px; padding: 5px 0;">
                        <ul class="list-unstyled d-flex align-items-center flex-wrap" style="gap: 15px; margin: 0;">
                            <!-- 1. 数据库IP地址：固定label宽度，input自适应剩余空间 -->
                            <li class="d-flex align-items-center" style="min-width: 280px;">
                                <label class="control-label" style="width: 100px; margin-right: 8px; text-align: right;">数据库IP地址：</label>
                                <input type="text" name="ipAddr" class="form-control" style="flex: 1; min-width: 150px;"/>
                            </li>
                            <!-- 2. 数据库名称：同IP布局，保持风格一致 -->
                            <li class="d-flex align-items-center" style="min-width: 280px;">
                                <label class="control-label" style="width: 100px; margin-right: 8px; text-align: right;">数据库名称：</label>
                                <input type="text" name="naDb" class="form-control" style="flex: 1; min-width: 150px;"/>
                            </li>
                            <!-- 3. 按钮组：margin-left: auto 自动顶到最右侧，自适应剩余空间 -->
                            <li class="d-flex align-items-center" style="margin-left: auto; padding-right: 10px;">
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm ml-2" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="test:database:add">
                    <i class="fa fa-plus"></i> 连接测试
                </a>
                <a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="test:database:edit">
                    <i class="fa fa-edit"></i> 修改
                </a>
                <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="test:database:remove">
                    <i class="fa fa-remove"></i> 删除
                </a>
<!--                <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="test:database:export">-->
<!--                    <i class="fa fa-download"></i> 导出-->
<!--                </a>-->
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('test:database:edit')}]];
        var removeFlag = [[${@permission.hasPermi('test:database:remove')}]];
        var prefix = ctx + "test/database";

        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                modalName: "数据连接",
                columns: [{
                    checkbox: true
                },
                {
                    field: 'dbId',
                    title: '数据连接序号',
                    visible: false
                },
                {
                    field: 'ipAddr',
                    title: '数据库IP地址'
                },
                {
                    field: 'port',
                    title: '数据库端口'
                },
                {
                    field: 'naDb',
                    title: '数据库名称'
                },
                {
                    field: 'username',
                    title: '数据库用户名'
                },
                {
                    field: 'password',
                    title: '数据库密码'
                },
                {
                    field: 'remark',
                    title: '备注'
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.dbId + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.dbId + '\')"><i class="fa fa-remove"></i>删除</a>');
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });
    </script>
</body>
</html>